home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
c
/
mc51bugs.zip
/
Q32017
< prev
next >
Wrap
Text File
|
1988-07-21
|
2KB
|
54 lines
Q32017 _Lrotl, _Lrotr Produce Incorrect Results when Compiled /Oi
C Compiler
5.10 | 5.10
MS-DOS | OS/2
Summary:
The intrinsic form of _lrotr and _lrotl produces incorrect code
when the result of the functions is assigned to an unsigned integer.
The correct output for the program below is as follows:
3
0
When compiled with /Oi (enables intrinsic functions), the output
for the program is as follows:
2
8000
More Information:
The program is as follows:
#include <stdlib.h>
#include <stdio.h>
main()
{
unsigned b;
unsigned c;
b = _lrotl(0x80000001L,1); /* rotate the hex value
80000001 one bit to the
left */
c = _lrotr(0x80000001L,1); /* rotate one bit to the
right */
printf("%x\n",b);
printf("%x\n",c);
}
The optimization erroneously causes the rotation to be performed on
an unsigned short rather than the designated unsigned long.
To work around this problem, type cast the result of the rotate
functions to an unsigned long before the assignment, as follows:
b = (unsigned long)_lrotl(0x80000001L,1);
c = (unsigned long)_lrotr(0x80000001L,1);
Microsoft has confirmed this to be a problem in Version 5.10 of the
C compiler. Microsoft is researching this problem and will post new
information as it becomes available.
Keywords: buglist5.10
Updated 88/07/21 03:19